import dao.PersionBeanDao;
import dao.RolePermissionDao;
import entity.Permission;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import pojo.PersionBean;
import pojo.StateBean;

import javax.annotation.Resource;
import java.util.List;

/**
 * @version 1.0
 * @Author: 举个栗子吖
 * @Date: 2019-11-20 8:33
 */
public class test {
    private static ApplicationContext applicationContext;
    @Resource(name = "persionBeanDao")
    private static PersionBeanDao persionBeanDao;
    @Autowired
    private static RolePermissionDao rolePermissionDao;

    static {
        applicationContext = new ClassPathXmlApplicationContext("spring.xml");
        persionBeanDao = (PersionBeanDao) applicationContext.getBean("persionBeanDao");
        rolePermissionDao = (RolePermissionDao) applicationContext.getBean("rolePermissionDao");
    }


    public static void testQueryPersionn() {
        List<PersionBean> lsit = persionBeanDao.query(2);
        System.out.println(lsit.size());
        for (PersionBean p : lsit) {
            System.out.println(p.getId() + "===" + p.getText());
        }
    }

    public static void testlist() {
        /*得到系统所有的权限*/
        List<Permission> list = rolePermissionDao.list();
        /*当前角色所拥有的权限*/
        List<Permission> list1 = rolePermissionDao.queryByRoleId(0);
        for (Permission permission : list) {
            StateBean stateBean = new StateBean();
            for (Permission persionBean1 : list1) {
                if (permission.getId() == persionBean1.getId()) {
                    stateBean.setChecked(true);
                }
            }
            permission.setStateBean(stateBean);
        }
        for (Permission p : list) {
            System.out.println(p.getName() + "---" + p.getStateBean().isChecked());
        }
    }

    public static void main(String[] args) {
        testlist();
    }


}
